package com.slofzx.nuoda.evaluation.project.controller;

import com.slofzx.nuoda.evaluation.project.dto.BatchInfoDTO;
import com.slofzx.nuoda.evaluation.project.dto.PlanInfoDTO;
import com.slofzx.nuoda.evaluation.project.dto.ProjectInfoDTO;
import com.slofzx.nuoda.evaluation.project.vo.BatchInfoNameVO;
import com.slofzx.nuoda.evaluation.project.vo.PlanInfoVO;
import com.slofzx.nuoda.evaluation.project.service.PlanInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import com.slofzx.nuoda.common.controller.BaseController;
import com.slofzx.nuoda.common.vo.AjaxResultVO;
import com.slofzx.nuoda.common.vo.PageResultVO;
import com.slofzx.nuoda.common.enums.ServiceResult;

import java.util.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 评价方案基本信息表控制层
 *
 * @author nuoda
 * @menu 评价方案基本信息表
 * @since 2024-03-15 09:21:38
 */
@RestController
@RequestMapping("/plan_info")
public class PlanInfoController extends BaseController {
    /**
     * 服务对象
     */
    @Autowired
    private PlanInfoService planInfoService;

    /**
     * 通过查询条件查询列表数据
     *
     * @param dto 查询参数
     * @return 列表数据
     */
    @GetMapping("/data")
    public AjaxResultVO<List<PlanInfoVO>> queryList(PlanInfoDTO dto) {
        List<PlanInfoVO> dataList = planInfoService.queryList(dto);
        return PageResultVO.newSuccessResult(dataList, dto.getCount());
    }
    @GetMapping("/nameList")
    public AjaxResultVO<List<BatchInfoNameVO>> queryNameList() {
        List<BatchInfoNameVO> dataList = planInfoService.queryNameList();
        return AjaxResultVO.newSuccessResult(dataList);
    }

    @ResponseBody
    @PostMapping(value = "/edit_common")
    public AjaxResultVO editCommonData(@RequestBody PlanInfoDTO dto) {
        ServiceResult resultEnum = planInfoService.editCommonData(dto);
        return AjaxResultVO.getInstance(resultEnum);
    }

    /**
     * 导入Excel
     */
    @PostMapping("/importExcel/{fileId}/{batchId}")
    public AjaxResultVO importExcel(@PathVariable String fileId,@PathVariable String batchId) {
        ServiceResult serviceResult = planInfoService.importExcel(fileId, batchId);
        return AjaxResultVO.getInstance(serviceResult);
    }

    @RequestMapping("/exportExcel")
    public ResponseEntity<byte[]> exportExcel(HttpServletRequest request, ProjectInfoDTO projectInfoDTO) {
        return planInfoService.exportExcel(request ,projectInfoDTO);
    }

    /**
     * 创建数据
     *
     * @param dto 参数数据
     * @return 操作结果
     */
    @ResponseBody
    @PostMapping(value = "/create")
    public AjaxResultVO create(@RequestBody PlanInfoDTO dto) {
        ServiceResult resultEnum = planInfoService.create(dto);
        return AjaxResultVO.getInstance(resultEnum);
    }

    /**
     * 数据更新
     *
     * @param dto
     * @return 操作结果
     */
    @ResponseBody
    @PostMapping(value = "/update")
    public AjaxResultVO update(@RequestBody PlanInfoDTO dto) {
        ServiceResult resultEnum = planInfoService.update(dto);
        return AjaxResultVO.getInstance(resultEnum);
    }
    /**
     * 方案锁定
     *
     * @param dto
     * @return 操作结果
     */
    @ResponseBody
    @PostMapping(value = "/lock")
    public AjaxResultVO lock(@RequestBody PlanInfoDTO dto) {
        ServiceResult resultEnum = planInfoService.lock(dto);
        return AjaxResultVO.getInstance(resultEnum);
    }
    /**
     * 方案解锁,只有有权限的用户才可以进行解锁
     *
     * @param dto
     * @return 操作结果
     */
    @ResponseBody
    @PostMapping(value = "/unlock")
    public AjaxResultVO unlock(@RequestBody PlanInfoDTO dto) {
        ServiceResult resultEnum = planInfoService.unlock(dto);
        return AjaxResultVO.getInstance(resultEnum);
    }

    /**
     * 删除数据
     *
     * @param id
     * @return 操作结果
     */
    @ResponseBody
    @PostMapping(value = "/delete")
    public AjaxResultVO delete(@RequestParam String id) {
        ServiceResult resultEnum = planInfoService.deleteById(id);
        return AjaxResultVO.getInstance(resultEnum);
    }

    /**
     * 查询单个数据
     *
     * @return id对应数据
     */
    @ResponseBody
    @GetMapping(value = "/info/{id}")
    public AjaxResultVO<PlanInfoVO> queryById(@PathVariable String id) {
        PlanInfoVO vo = planInfoService.queryById(id);
        return AjaxResultVO.newSuccessResult(vo);
    }

}
